<template>
    <Card style="width:100%" class="detail-content-layout mb16">
        <template #title>
            {{ $t('确定供应商') }}
        </template>
        <template #extra>
            <!--        @click="printPdf(info)"-->

            <Icon @click="printPreviewPdf('SOC',info)" style="font-size: 19px; margin-right: 10px;" type="ios-print"/>
            <div class="h-arrow-wrap" @click="toggle = !toggle">
                <i :class="{toggleActive:toggle}" class="iconfont zy-common-jiantou h-arrow-icon"></i>
            </div>
        </template>
        <transition name="slide-up">
            <div v-if="toggle">
                <Form ref="form" :model="form" :rules="rules" label-position="top">
                    <Row :gutter="24">
                        <Col span="6">
                            <FormItem :label="$t('许可证号码')" prop="cerNumber">
                                <Input maxlength="100" :disabled="disabled" clearable type="text"
                                       v-model="form.cerNumber"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('部门')" prop="cvDepartmentId">
                                <Select
                                    transfer
                                    v-if="!disabled"
                                    v-model="form.cvDepartmentId"
                                    clearable
                                    :label-in-value="true"
                                    :disabled="disabled"
                                    :placeholder="`${$t('common.selectInfo')}`"
                                >
                                    <Option
                                        v-for="(item, index) of dpList"
                                        :value="item.label"
                                        :key="index"
                                        :label="item.label"
                                        :tag="item.label"
                                    />
                                </Select>
                                <Input v-else disabled clearable type="text" v-model="form.cvDepartmentId"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('PR编号')" prop="prNo">
                                <Input maxlength="100" :disabled="disabled" clearable type="text"
                                       v-model.number="form.prNo"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('部门成本中心')" prop="departmentCostCenter">
                                <Input maxlength="100" :disabled="disabled" clearable type="text"
                                       v-model.number="form.departmentCostCenter"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('地址')" prop="location">
                                <Input maxlength="100" :disabled="disabled" clearable type="text"
                                       v-model.number="form.location"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('商业目的')" prop="businessPurpose">
                                <Select
                                    transfer
                                    :disabled="disabled"
                                    v-model="form.businessPurpose"
                                    filterable
                                    clearable
                                    multiple
                                    :placeholder="`${$t('common.selectInfo')}`"
                                >
                                    <Option v-for="(item,index) in businessPurposeList" :key="index" :value="item.label"
                                            :label="item.label"></Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('购置方式')" prop="acquisitionMethod">
                                <Select
                                    transfer
                                    :disabled="disabled"
                                    v-model="form.acquisitionMethod"
                                    filterable
                                    clearable
                                    :placeholder="`${$t('common.selectInfo')}`"
                                >
                                    <Option v-for="(item,index) in acquisitionMethodList" :key="index"
                                            :value="item.label"
                                            :label="item.label"></Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="6" v-if="form.acquisitionMethod === 'Direct Replacement'">
                            <FormItem :label="$t('被替换设备的年龄')" prop="ageOfReplacedEquipment">
                                <Input maxlength="100" :disabled="disabled" clearable type="number"
                                       v-model.number="form.ageOfReplacedEquipment"
                                       :placeholder="$t('请输入')">
                                    <template slot="append">
                                        <span>Year</span>
                                    </template>
                                </Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('资本类别')" prop="capitalCategories">
                                <Select
                                    transfer
                                    :disabled="disabled"
                                    v-model="form.capitalCategories"
                                    filterable
                                    clearable
                                    multiple
                                    :placeholder="`${$t('common.selectInfo')}`"
                                >
                                    <Option v-for="(item,index) in capitalCategoriesList" :key="index"
                                            :value="item.label"
                                            :label="item.label"></Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="6" style="height: 79px">
                            <FormItem :label="$t('该项目是否包括在资本预算中')" prop="inCapitalBudget" required>
                                <RadioGroup v-model="form.inCapitalBudget" :disabled="disabled">
                                    <Radio :disabled="disabled" :label=1>{{ $t('是') }}</Radio>
                                    <Radio :disabled="disabled" :label=0>{{ $t('否') }}</Radio>
                                </RadioGroup>
                            </FormItem>
                        </Col>
                        <Col span="6" v-if="disabled">
                            <FormItem :label="$t('要求的是')">
                                <Input maxlength="100" disabled clearable type="text" v-model="form.requestedBy"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6">
                            <FormItem :label="$t('延伸')">
                                <Input maxlength="500" :disabled="disabled" clearable type="text" v-model="form.ext"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="24">
                            <FormItem :label="$t('项目简述')">
                                <Input show-word-limit maxlength="4000" :disabled="disabled" clearable type="textarea"
                                       :rows="4" v-model="form.projectShortDescription"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                    </Row>
                    <div class="tableContent mb16">
                        <p class="tax">{{ $t('不含税资本总额') }}</p>
                        <Table class="resizable-table"
                               @on-column-width-resize="(a,b,c,d)=>{onColumnWidthResize(a,b,c,d,'confirmVendor')}"
                               border :columns="columns" :data="dataSource">
                            <template slot-scope="{ row,index }" slot="action">
                                <div class="ivu-table-cell-slot">
                                  <span class="operationBtn" v-if="row.operation ==='action' && !disabled"
                                        @click="addItem">{{ $t('新增') }}</span>
                                    <span v-if="row.operation !=='action' && !disabled" class="operationBtn"
                                          @click="removeItem(index)">{{ $t('删除') }}</span>
                                    <span
                                        v-if="row.operation !=='action' && !row.edit  && (!disabled || cvRepeatTagging==1) "
                                        class="operationBtn"
                                        @click="editItem(index)">{{ row.edit ? $t('更新') : $t('编辑') }}</span>
                                    <span
                                        v-if="row.operation !=='action' && row.edit  &&  (!disabled || cvRepeatTagging==1)"
                                        class="operationBtn"
                                        @click="saveItem(index)">{{ $t('提交') }}</span>
                                    <span
                                        v-if="row.operation !=='action' && row.edit  &&  (!disabled || cvRepeatTagging==1)"
                                        class="operationBtn"
                                        @click="cancelSaveItem(index)">{{ $t('取消') }}</span>
                                </div>
                            </template>
                            <template slot-scope="{ row,index }" slot="index">
                                <p v-if="row.operation !=='action'" style="text-align: left">{{ index + 1 }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="slot1">
                                <Input maxlength="200" v-model.trim="dataSource[index].description"
                                       :placeholder="$t('请输入')"
                                       v-if="row.operation !=='action'  && row.edit && !cvRepeatTagging"/>
                                <p style="text-align: left" v-else>{{ dataSource[index].description }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="slot2">
                                <Input maxlength="200" v-model.trim="dataSource[index].type" :placeholder="$t('请输入')"
                                       v-if="row.operation !=='action'  && row.edit && !cvRepeatTagging"/>
                                <p style="text-align: left" v-else>{{ dataSource[index].type }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="slot3">
                                <Input maxlength="200" v-model.trim="dataSource[index].vendor" :placeholder="$t('请输入')"
                                       v-if="row.operation !=='action'  && row.edit && cvRepeatTagging==1"/>
                                <p style="text-align: left" v-else>{{ dataSource[index].vendor }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="slot4">
                                <InputNumber class="tableInputNumber" size="mini" max="999999999" type="number"
                                             v-model.trim="dataSource[index].quantity" :placeholder="$t('请输入')"
                                             v-if="row.operation !=='action'  && row.edit && !cvRepeatTagging"/>
                                <p style="text-align: left" v-else>{{ dataSource[index].quantity }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="slot5">
                                <InputNumber class="prependMoneyIcon prependIcon tableInputNumberbr" style="width: 100%"
                                             size="mini" clearable
                                             max="999999999" type="number" v-model.trim="dataSource[index].currency"
                                             :placeholder="$t('请输入')"
                                             :formatter="value => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/k\￥\s?|(,*)/g, '')"
                                             v-if="row.operation !=='action'  && row.edit  && cvRepeatTagging==1"/>
                                <p style="text-align: left" v-else v-show="row.operation !=='action'">
                                    {{
                                        (dataSource[index].currency ? "￥" + dataSource[index].currency : "")   | thousandth
                                    }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="slot6">
                                <p style="text-align: left;" v-if="row.operation !=='action'">
                                    {{
                                        (dataSource[index].quotationCost ? "￥" + dataSource[index].quotationCost : "") | thousandth
                                    }}</p>
                                <p style="text-align: left;" v-else>{{ formatQuotationCost() | thousandth }}</p>
                            </template>
                            <template slot-scope="{ row,index }" slot="upload">
                                <div>
                                    <uploadFile :fileList="row.capexFilePo" :disabled="cvRepeatTagging!=1 || !row.edit"
                                                v-if="row.operation !=='action'" type="button"
                                                @change="(files)=>{dataSource[index].capexFileDtos = files}"/>
                                </div>
                            </template>
                            <template slot-scope="{ row,index }" slot="remark">
                                <Input maxlength="200" v-model.trim="dataSource[index].remark" :placeholder="$t('请输入')"
                                       v-if="row.operation !=='action'  && row.edit && (!cvRepeatTagging || cvRepeatTagging == 1) "/>
                                <p style="text-align: left" v-else>{{ dataSource[index].remark }}</p>
                            </template>
                        </Table>
                    </div>
                    <Row :gutter="16" v-if="cvRepeatTagging==1 || cvRepeatTagging==2 || disabled">
                        <Col span="6" v-if="info.cvInfo.sourcingEngineer">
                            <FormItem :label="$t('采购工程师')">
                                <Input disabled clearable type="text" v-model="form.sourcingEngineer"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                        <Col span="6"
                             v-if="(cvRepeatTagging==2 && disabled) || (disabled && form.budgetBalBfApproval) ">
                            <FormItem :label="$t('今年的预算')" prop="budgetThisYear">
                                <InputNumber class="prependMoneyIcon prependIcon" max="999999999" style="width: 100%"
                                             :disabled="isDisabled()"
                                             clearable type="number" number v-model.number="form.budgetThisYear"
                                             :formatter="value => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/k\￥\s?|(,*)/g, '')"
                                             :placeholder="$t('请输入')">
                                    <!--                             :formatter="value => `k￥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"-->
                                    <!--                             :parser="value => value.replace(/k\￥\s?|(,*)/g, '')">-->
                                </InputNumber>
                            </FormItem>
                        </Col>
                        <Col span="6"
                             v-if="(cvRepeatTagging==2 && disabled) || (disabled && form.budgetBalBfApproval) ">
                            <FormItem :label="$t('预算余额 Bf. 审批')" prop="budgetBalBfApproval">
                                <InputNumber class="prependMoneyIcon prependIcon" max="999999999" style="width: 100%"
                                             :disabled="isDisabled()"
                                             clearable type="number" number v-model.number="form.budgetBalBfApproval"
                                             :formatter="value => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
                                             :parser="value => value.replace(/k\￥\s?|(,*)/g, '')"
                                             :placeholder="$t('请输入')">
                                </InputNumber>
                            </FormItem>
                        </Col>
                        <Col span="6" v-if="form.financeSubmittedBy">
                            <FormItem :label="$t('财务部提交的')">
                                <Input disabled clearable type="text" v-model="form.financeSubmittedBy"
                                       :placeholder="$t('请输入')"></Input>
                            </FormItem>
                        </Col>
                    </Row>
                    <rejectInfo :rejectFlows="rejectFlows"/>
                </Form>
            </div>
        </transition>


    </Card>
</template>

<script>

import mixins from "@/views/devBasic/capex/components/mixins";
import rejectInfo from "@/views/devBasic/capex/components/rejectInfo";
import uploadFile from "@/views/devBasic/capex/components/uploadFile";


const totalComlums = {quotationCost: "", amount: 0, operation: "action", id: "", edit: false, vendor: ""}
export default {
    name: "bdgApproval",
    components: {rejectInfo, uploadFile,},
    mixins: [mixins],
    props: {
        info: {
            type: Object,
            default: () => {
            }
        },
        disabled: {
            type: Boolean,
            default: false
        },
        approvalInfo: {
            type: Object,
            default: () => {
            }
        },
        rejectFlows: {
            type: Object,
            default: () => {
            }
        },
        expand: {
            type: Boolean,
            default: false
        }
    },
    data() {
        const validateInput = (rule, value, callback) => {
            if (!value) {
                callback(new Error(this.$t('请输入')));
            } else {
                callback();
            }
        };
        const validateAgeOfReplacedEquipment = (rule, value, callback) => {
            if (!this.form.ageOfReplacedEquipment && this.form.acquisitionMethod === 'Direct Replacement') {
                callback(new Error(this.$t('请输入')));
            } else {
                callback();
            }
        };
        const validateInCapitalBudget = (rule, value, callback) => {
            if (value != 0 && !value) {
                callback(new Error(this.$t('请选择')));
            } else {
                callback();
            }
        };
        const validsElect = (rule, value, callback) => {
            if (value != 0 && !value) {
                callback(new Error(this.$t('请选择')));
            } else {
                callback();
            }
        };
        return {
            iframeShow: false,
            iframeModalSrc: '',
            infoId: "",
            toggle: false,
            form: {
                cerNumber: "",
                cvDepartmentId: "",
                departmentCostCenter: "",
                businessPurpose: [],
                acquisitionMethod: "",
                capitalCategories: "",
                inCapitalBudget: "",
                ext: "",
                budgetThisYear: "",
                budgetBalBfApproval: ""
            },
            rules: {
                cerNumber: [{required: true, type: 'string', message: this.$t('请输入'), trigger: 'change'}],
                cvDepartmentId: [{required: true, type: "string", message: this.$t('请输入'), trigger: 'change'}],
                departmentCostCenter: [{required: true, trigger: 'change', validator: validateInput}],
                businessPurpose: [{required: true, type: 'array', message: this.$t('请输入'), trigger: 'change'}],
                acquisitionMethod: [{required: true, type: 'string', message: this.$t('请输入'), trigger: 'change'}],
                capitalCategories: [{required: true, type: 'array', message: this.$t('请输入'), trigger: 'change'}],
                inCapitalBudget: [{validator: validateInCapitalBudget, trigger: 'change'}],
                ageOfReplacedEquipment: [{trigger: 'change', validator: validateAgeOfReplacedEquipment}],
                budgetThisYear: [{required: true, trigger: 'change', validator: validateInput}],
                budgetBalBfApproval: [{required: true, trigger: 'change', validator: validateInput}],
            },
            dataSource: [{...totalComlums}],
            columns: [
                {
                    title: this.$t('项目编号'),
                    key: "processCode",
                    slot: "index",
                    resizable: true
                },
                {
                    title: this.$t('描述'),
                    key: "description",
                    slot: "slot1",
                    renderHeader: (h) => {
                        return h('div', [
                            h('span', {
                                domProps: {
                                    innerHTML: this.$t('描述')
                                },
                                attrs: {
                                    class: "required "
                                }
                            }),
                        ])
                    },
                    resizable: true
                },
                {
                    title: this.$t('类型'),
                    key: "type",
                    slot: "slot2",
                    resizable: true,tooltip: true,
                    renderHeader: (h) => {
                        return h('div', [
                            h('span', {
                                domProps: {
                                    innerHTML: this.$t('类型')
                                },
                                attrs: {
                                    class: "required "
                                }
                            }),
                        ])
                    }
                },
                {
                    title: this.$t('数量'),
                    key: "quantity",
                    slot: "slot4",
                    resizable: true,tooltip: true,
                    renderHeader: (h) => {
                        return h('div', [
                            h('span', {
                                domProps: {
                                    innerHTML: this.$t('数量')
                                },
                                attrs: {
                                    class: "required "
                                }
                            }),
                        ])
                    }
                },
                {
                    title: this.$t('供应商'),
                    key: "vendor",
                    slot: "slot3",
                    resizable: true,tooltip: true,
                    renderHeader: (h) => {
                        return h('div', [
                            h('span', {
                                domProps: {
                                    innerHTML: this.$t('供应商')
                                },
                                attrs: {
                                    class: "required "
                                }
                            }),
                        ])
                    }
                },
                {
                    title: this.$t('货币'),
                    key: "currency",
                    slot: "slot5",
                    resizable: true,tooltip: true,
                    // renderHeader: (h) => {
                    //     return h('div', [
                    //         h('span', {
                    //             domProps: {
                    //                 innerHTML: this.$t('货币')
                    //             },
                    //             attrs: {
                    //                 class: "required "
                    //             }
                    //         }),
                    //     ])
                    // }
                },
                {
                    title: this.$t('附件'),
                    key: "quotationCost",
                    slot: "upload",
                    resizable: true,tooltip: true,
                    renderHeader: (h) => {
                        return h('div', [
                            h('span', {
                                domProps: {
                                    innerHTML: this.$t('附件')
                                }
                            }),
                            h('Tooltip', {
                                    attrs: {
                                        content: this.$t('请附供应商报价细节。')
                                    },
                                    props: {
                                        transfer: true,
                                        maxWidth: 200
                                    }
                                },
                                [h('Icon', {
                                        attrs: {
                                            type: "md-information-circle"
                                        }
                                    },
                                ),]
                                //
                            )
                        ])
                    }
                },
                {
                    title: this.$t('报价成本'),
                    key: "quotationCost",
                    slot: "slot6",
                    resizable: true
                    // width: 120,
                },
                {
                    title: this.$t('备注'),
                    key: "remark",
                    slot: "remark",
                    resizable: true
                    // width: 120,
                },
                {
                    title: this.$t('操作'),
                    key: "Items",
                    slot: "action",
                    width: 200,
                    align: "center",
                    fixed: "right"
                }
            ],
            dpList: [],
            cvRepeatTagging: 0,
            lastList: [],
            lastForm: {}
        }
    },
    async mounted() {
        this.getColumnWidth(this.columns, 'confirmVendor')
        this.form.submitByStr = this.userName

        this.cvRepeatTagging = this.info.cvRepeatTagging / 1


        if (this.info.cvInfo && this.info.cvInfo.id) {
            // this.form.inCapitalBudget = this.info.exceedsBudget/1
            this.toggle = true
            this.form.inCapitalBudget = this.info.exceedsBudget
            if (this.cvRepeatTagging == 1 || this.cvRepeatTagging == 2) {
                this.disabled = true
                // this.toggle = true
            }
            this.setParams()
        } else {
            const companyObj = this.companyList.find(item => item.value === this.info.mainCompanyName / 1)
            this.form.cerNumber = this.info.mainProjectId
            this.form.location = companyObj ? companyObj.label:""

        }

        if (!this.disabled) {
            this.toggle = true
            this.form.inCapitalBudget = this.info.exceedsBudget
            this.form.requestedBy = this.userName


            if (this.cvRepeatTagging == 1 || this.cvRepeatTagging == 2) {
                this.disabled = true
            }
            this.dpList = await this.getdpList()
        }

        if (this.disabled && !(this.cvRepeatTagging == 1 || this.cvRepeatTagging == 2)) {
            this.toggle = false
        }

        if (this.expand) {
            this.toggle = true
        }


    },
    methods: {
        printPdf(info) {
            this.iframeModalSrc = '/capital'
            this.infoId = info.id
            this.iframeShow = true
        },
        isDisabled() {
            if (this.cvRepeatTagging == 2) {
                return false
            } else if (this.cvRepeatTagging == 1 || this.cvRepeatTagging == 0) {
                return true
            } else {
                return this.disabled
            }
        },
        formatQuotationCost() {

            let total = 0
            this.dataSource.forEach(item => {
                if (item.quantity && item.currency) {
                    item.quotationCost = item.quantity * item.currency
                } else {
                    item.quotationCost = ""
                }
                total = total + (item.quotationCost || 0)
            })

            return total > 0 ? '￥' + total : ''
        },
        saveItem(index) {

            this.activeIndex = index
            if (!this.dataSource[this.activeIndex].processCode) {
                this.$Message.error(this.$t('请输入'))
                return;
            }

            if (!this.dataSource[this.activeIndex].description) {
                this.$Message.error(this.$t('请输入'))
                return;
            }
            if (!this.dataSource[this.activeIndex].type) {
                this.$Message.error(this.$t('请输入'))
                return;
            }
            if (!this.dataSource[this.activeIndex].vendor && this.cvRepeatTagging == 1) {
                this.$Message.error(this.$t('请输入'))
                return;
            }
            if (!this.dataSource[this.activeIndex].quantity) {
                this.$Message.error(this.$t('请输入'))
                return;
            }
            // if (!this.dataSource[this.activeIndex].currency && this.cvRepeatTagging == 1) {
            //     this.$Message.error(this.$t('请输入'))
            //     return;
            // }
            // if (!(Array.isArray(this.dataSource[this.activeIndex].capexFileDtos) && this.dataSource[this.activeIndex].capexFileDtos.length > 0)) {
            //   this.$Message.error(this.$t('请上传附件'))
            //   return;
            // }


            this.dataSource[this.activeIndex]['edit'] = false
            this.$forceUpdate()
        },
        cancelSaveItem(index) {
            const obj = this.copyDataSource.find(item => {
                if (this.dataSource.find(m => m.processCode === item.processCode))
                    return item
            })
            if (obj)
                this.dataSource.splice(index, 1, {...obj, edit: false})
            else
                this.dataSource.splice(index, 1)
        },
        checkEditStatus() {
            const obj = this.dataSource.find(item => item.edit)
            if (obj) {
                this.$Message.error(this.$t('请先保存'))
                return true
            } else {
                return false
            }
        },
        editItem(index) {
            if (this.checkEditStatus()) return false
            this.dataSource[index]['edit'] = true
            this.activeIndex = index
            this.copyDataSource = JSON.parse(JSON.stringify(this.dataSource))
            this.$forceUpdate()
        },
        addItem() {

            if (this.checkEditStatus()) return false
            const id = this.dataSource.length > 1 ? (this.dataSource[this.dataSource.length - 2].processCode || 0) + 1 : 1
            const obj = {
                processCode: id,
                description: "",
                type: "",
                vendor: "",
                quantity: "",
                currency: "",
                quotationCost: "",
                edit: true
            }
            this.dataSource.splice(this.dataSource.length - 1, 0, obj)
        },
        removeItem(index) {
            this.dataSource.splice(index, 1)
        },
        setParams() {
            const {submitRemark, submitTime, submitByStr} = this.approvalInfo
            const {
                processCode,
                cerNumber,
                cvDepartmentId,
                departmentCostCenter,
                businessPurpose,
                acquisitionMethod,
                ageOfReplacedEquipment,
                capitalCategories,
                inCapitalBudget,
                requestedBy,
                projectShortDescription,
                location,
                ext,
                sourcingEngineer,
                financeSubmittedBy,
                budgetThisYear,
                budgetBalBfApproval
            } = this.info.cvInfo || {}
            const {prNo, cvDetails} = this.info
            this.form = Object.assign(this.form, {
                remark: submitRemark,
                submitTime,
                submitByStr,
                processCode,
                cerNumber,
                cvDepartmentId,
                departmentCostCenter,
                businessPurpose: businessPurpose ? businessPurpose.split(',') : [],
                acquisitionMethod,
                ageOfReplacedEquipment,
                capitalCategories: capitalCategories ? capitalCategories.split(',') : [],
                inCapitalBudget: inCapitalBudget / 1,
                requestedBy,
                projectShortDescription,
                location,
                prNo,
                ext,
                sourcingEngineer,
                financeSubmittedBy,
                budgetThisYear,
                budgetBalBfApproval
            })

            this.lastForm = JSON.parse(JSON.stringify(this.form))


            if (this.cvRepeatTagging == 1) {
                this.form.sourcingEngineer = ""
                this.form.financeSubmittedBy = ""
            }
            if (this.cvRepeatTagging == 2) {
                this.form.financeSubmittedBy = ""
            }

            // if (this.cvRepeatTagging != 2 && this.cvRepeatTagging != 1){
            //   this.form.financeSubmittedBy = this.userName
            // }


            cvDetails.forEach((item, index) => {
                item.processCode = index + 1
                item.edit = false
                item.capexFileDtos = item.capexFilePo || []
                if (this.cvRepeatTagging == 1) {
                    item.edit = true
                }
            })
            this.dataSource = JSON.parse(JSON.stringify(cvDetails))
            // if (type)
            this.dataSource.push(totalComlums)

            this.copyDataSource = JSON.parse(JSON.stringify(this.dataSource))
            // this.form.requestedBy = this.userName
            this.$forceUpdate()
        },
        async getParams(status) {
            if (this.checkEditStatus()) return false

            let valid = true;
            let hasFieldChange = false;

            if (this.cvRepeatTagging == 0 || this.cvRepeatTagging == 2) {
                valid = (status && this.cvRepeatTagging == 0) ? status : await this.$refs.form.validate()
            }

            let list = JSON.parse(JSON.stringify(this.dataSource))
            if (Array.isArray(list) && list.length > 0)
                list.splice(list.length - 1, 1)

            if (!status) {
                if (list.find(item => item.edit)) {
                    this.$Message.error(this.$t('请先保存'))
                    return;
                }

                if (list.length < 1) {
                    this.$Message.error(this.$t('最少添加一条数据'))
                    return;
                }
            }

            if (this.cvRepeatTagging == 1) {
                hasFieldChange = this.detectionFieldMethod(list, this.dataSource, ['vendor', 'currency', 'quotationCost', 'remark'])
            }
            if (this.cvRepeatTagging == 2) {
                let {budgetThisYear, budgetBalBfApproval} = this.lastForm;
                let budgetThisYearForm = this.form.budgetThisYear
                let budgetBalBfApprovalForm = this.form.budgetBalBfApproval
                if (budgetThisYear)
                    budgetThisYear = budgetThisYear / 1
                if (budgetBalBfApproval)
                    budgetBalBfApproval = budgetBalBfApproval / 1
                if (budgetThisYearForm)
                    budgetThisYearForm = budgetThisYearForm / 1
                if (budgetBalBfApprovalForm)
                    budgetBalBfApprovalForm = budgetBalBfApprovalForm / 1

                hasFieldChange = (budgetThisYear===budgetThisYearForm) || (budgetBalBfApproval===budgetBalBfApprovalForm)
            }

            const {businessPurpose = [], capitalCategories = []} = this.form

            if (valid) {
                return {
                    cvInfo: {
                        ...this.form,
                        businessPurpose: (businessPurpose || []).join(','),
                        capitalCategories: (capitalCategories || []).join(',')
                    },
                    cvDetails: list,
                    cvRepeatTagging: this.info.cvRepeatTagging,
                    hasFieldChange
                }
            }
        }
    }
}
</script>

<style scoped lang="scss">
@import "./style";



.tableInputNumberbr {
    border: 1px solid #dcdee2;

    ::v-deep .ivu-input-number-input {
        border: none;
    }
}
</style>

